package pers.xiaoliang.concurrency.example.count;

import lombok.extern.slf4j.Slf4j;
import pers.xiaoliang.concurrency.annotation.ThreadSafe;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @version v1.0
 * @description: 计数器例子2 使用AtomicReference
 * @author: xiaoliang.liu
 * @date: 2018/7/26 21:31
 */
@Slf4j
@ThreadSafe
public class CountExample3 {

    private static AtomicReference<Integer> count = new AtomicReference<>(0);

    public static void main(String[] args) {
        count.compareAndSet(0, 2);
        count.compareAndSet(0, 1);
        count.compareAndSet(1, 3);
        count.compareAndSet(2, 4);
        count.compareAndSet(3, 5);
        log.info(String.valueOf(count.get()));
    }
}
